#include <bits/stdc++.h>

using namespace std;

class Solution {
   public:
    long long pickGifts(vector<int>& gifts, int k) {
        long long ans = 0;
        priority_queue<int> heap;
        for (auto  e : gifts){
            heap.push(e);
            ans += e;
        }
        while (k--){
            int e = heap.top();
            ans -= e;
            heap.pop();
            heap.push(sqrt(e));
            ans += sqrt(e);
        }
        return ans;
    }
};